package com.googlecode.xapper

import static org.junit.Assert.*
import static org.hamcrest.Matchers.*

import nu.xom.*

import com.googlecode.xapper.HtmlElementWrapper
import org.junit.Test

public class TestConvenienceMethodsInElementWrapper{

	def context = new XPathContext("html", "http://www.w3.org/1999/xhtml");
	def static XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
	
	@Test
	public void shouldWrapParagraphAfterConstructingAParagraph() {
		
		def element = HtmlElementWrapper.create("div")
			.withParagraph()
			.asElement()
		
		assertThat(element.getLocalName(), is(equalTo("p")))
	}
	
	@Test
	public void shouldWrapParagraphAfterConstructingAHeading() {
		
		def element = HtmlElementWrapper.create("div")
			.withHeading(1, "Hello")
			.asElement()
		
		assertThat(element.getLocalName(), is(equalTo("h1")))
	}
	
	@Test
	public void shouldWrapADivWhenRequested() {
		def element = HtmlElementWrapper.create("div")
			.withDiv()
			.asElement()
		
		assertThat(element.getLocalName(), is(equalTo("div")))
	}
	
	@Test
	public void shouldAddAnIdAttribute() {
		def element = HtmlElementWrapper.create("p")
			.withId("anId")
			.asElement()
		
		assertThat(element.getAttributeValue("id"), is(equalTo("anId")))
	}
	
	@Test
	public void shouldAddAClassAttribute() {
		def element = HtmlElementWrapper.create("div")
			.withClass("my-class")
			.asElement()
		
		assertThat(element.getAttributeValue("class"), is(equalTo("my-class")))
	}
	
	@Test
	public void shouldCreateAPage() {
		def body = HtmlElementWrapper.createPage().asElement()
		
		assertThat(body.getLocalName(), is("body"))
	}
}
